package com.acme.bankapp.service.email;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import com.acme.bankapp.domain.email.*;
import com.acme.bankapp.domain.email.impl.QueueImpl;

public class EmailService {
	private volatile static EmailService instance = null;
	private Queue<Email> queue;
	private static Object monitor = new Object();
	
	public Queue<Email> getQueue(){
		return queue;
	}

	public static EmailService getEmailService() {
		 if (instance == null) {
	            synchronized(monitor) {
	                if (instance == null)
	                	instance = new EmailService();
	            }
	        }
	        return instance;
	}
	
	private EmailService() {
		queue = new QueueImpl<Email>(5);
	}

	public void sendNotificationEmail(Email email) {
			try {
				queue.addEmail(email);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}	
	}
	
	public void close() {
		queue.close();
	}

}
